import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

import { setMain } from './utils/global'

// createApp(App)
//   .use(store)
//   .use(router)
  // .mount("#app");


let instance = null;

function render() {
  instance = createApp(App);
  instance
    .use(router)
    .mount('#app');
}

if (!window.__MICRO_WEB__) {
  render();
}

export async function bootstrap() {
  console.log('vue3.0 app bootstrap');
}

export async function mount(app) {
  // 测试沙箱: SnapShotSandbox.js
  window.a = 1;
  // 测试主应用中自定义事件
  window.custom.emit('test', {
    a: 1
  })
  
  // 子应用中测试全局store测试
  const storeData = window.store.getStore();

  window.store.subscribe((newVal,oldVal) => {
    console.log('childApp-newVal,oldVal==========', newVal,oldVal)
  })

  window.store.update({
    ...storeData,
    name: 'mapping'
  })


  // setMain(app)
  render();
  console.log('vue3.0 app mount')
}

export async function unmount(app) {
  // setMain(app)
  // render();
  console.log('vue3.0 app  unmount')
  
}

// export async function unmount(ctx) {
//   instance.unmount();
//   instance = null;
//   const { container } = ctx
//   if (container) {
//     document.querySelector(container).innerHTML = ''
//   }
// }
